package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/15 21:27
 **/
public class Day13_3_Num437_PathSum {
    class Solution {
        long ans = 0;
        public int pathSum(TreeNode root, int targetSum) {
            if(root == null) return 0;
            findPath(root, targetSum);
            pathSum(root.left, targetSum);
            pathSum(root.right, targetSum);
            return (int)ans;
        }
        private void findPath(TreeNode root, long targetSum){
            if(root == null) return;
            targetSum -= root.val;
            if(targetSum == 0) ans++;

            findPath(root.left, targetSum);
            findPath(root.right, targetSum);
        }
    }
}